﻿using AutoMapper;
using B.S.Sterilizationcenter.Domain.zmc;
using B.S.Sterilizationcenter.ErrorCode;
using B.S.Sterilizationcenter.Writer.API.Appliaction.Commends.Zmc.Instrumentkit;
using MediatR;
using SqlSugar;

namespace B.S.Sterilizationcenter.Writer.API.Appliaction.CommandHandlers.Zmc.Instrumentkit
{
    public class DelInstrumentkitCommendHandlers : IRequestHandler<DelInstrumentkitCommends, ApiResult<int>>
    {

        private readonly ISqlSugarClient db;
        private readonly IMapper mapper;

        public DelInstrumentkitCommendHandlers(ISqlSugarClient db, IMapper mapper)
        {
            this.db = db;
            this.mapper = mapper;
        }


        /// <summary>
        /// 删除器械包--逻辑删除
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<ApiResult<int>> Handle(DelInstrumentkitCommends request, CancellationToken cancellationToken)
        {
            ApiResult<int> result= new ApiResult<int>();
            var del = await db.Queryable<Instrumentkits>().FirstAsync(p => p.InstrumentkitsId == request.InstrumentkitsId);
            del.IsDeletes = true;
            var res = await db.Updateable<Instrumentkits>(del).ExecuteCommandAsync();
            if (res > 0)
            {
                result.Code = ApiEnums.删除成功;
                result.Msg = "删除成功";
            }
            else
            {
                result.Code = ApiEnums.删除失败;
                result.Msg = "删除失败";
            }
            return result;
        }
    }
}
